package org.yly.game.rpggame.domain.model.goods;

import java.util.Set;

import org.yly.game.rpggame.domain.model.CustomProperty;
import org.yly.game.rpggame.domain.model.PropertyName;
import org.yly.game.rpggame.domain.model.UpgradeEntity;

/**
 * 物品
 * 
 * @author makefu
 * 
 */
public class Goods extends UpgradeEntity {

	/* 基本信息 */
	private String name; // 名字
	private String description; // 描述
	private int repairMoney; // 修理费

	/* 使用限制 */
	private int playerLevel; // 玩家等级
	private String roleId; // 所属角色

	private GoodsState goodsState; // 物品状态

	public Goods(String id, String name, String description, int playerLevel, String roleId,
			Set<CustomProperty> propertySet) {
		super(id, propertySet);
		this.name = name;
		this.description = description;
		this.playerLevel = playerLevel;
		this.roleId = roleId;
		this.goodsState = new GoodsState(id);
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public GoodsState getGoodsState() {
		return goodsState;
	}
	
	/**
	 * 验证角色和等级是否正确
	 * @param roleId 玩家角色
	 * @param playerLevel 玩家等级
	 * @return
	 */
	public boolean canUse(String roleId, int playerLevel) {
		return this.roleId == roleId && this.playerLevel < playerLevel;
	}
	
	/**
	 * 获得物品当前状态的修理费
	 * @return
	 */
	public int getRepairMoney() {
		CustomProperty property = this.getCustomProperty(PropertyName.LossValue);
		if (property != null) {
			return property.getValue() / 100 * repairMoney;
		}
		return 0;
	}
	
}
